﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Ewk.Runtime.Serialization.CustomDatafieldSerializers.UnitTests.Datarecords;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Runtime.Serialization.CustomDatafieldSerializers.UnitTests.PositionBased
{
    [TestClass]
    public class DatarecordSerializerTests
    {
        [TestMethod]
        public void DatarecordSerializer_can_serialize_a_valid_PositionBasedTestDatarecordWithBooleanSerializer()
        {
            AssertSerializePositionBasedTestDatarecordWithBooleanSerializer(true, "Y");
            AssertSerializePositionBasedTestDatarecordWithBooleanSerializer(false, "N");
        }

        [TestMethod]
        public void DatarecordSerializer_can_deserialize_a_valid_PositionBasedTestDatarecordWithBooleanSerializer()
        {
            AssertDeserializePositionBasedTestDatarecordWithBooleanSerializer("Y", true);
            AssertDeserializePositionBasedTestDatarecordWithBooleanSerializer("N", false);
        }

        static void AssertSerializePositionBasedTestDatarecordWithBooleanSerializer(bool value, string expectedResult)
        {
            var record = new PositionBasedTestDatarecordWithBooleanSerializer { Field = value };

            var serializer = new DatarecordSerializer<PositionBasedTestDatarecordWithBooleanSerializer>();
            var result = serializer.Serialize(record);

            Assert.AreEqual(expectedResult, result);
        }

        static void AssertDeserializePositionBasedTestDatarecordWithBooleanSerializer(string value, bool expectedResult)
        {
            var serializer = new DatarecordSerializer<PositionBasedTestDatarecordWithBooleanSerializer>();
            var result = serializer.Deserialize(value);

            Assert.AreEqual(expectedResult, result.Field);
        }
    }
}
